/*
 * @Author: bom
 * @Version: V1.0
 * @Date: 2025-04-24 20:04:14
 * @LastEditTime: 2025-05-26 16:28:53
 * @FilePath: \myCAN (1)\myCan.cpp
 * @Description: 
 */
#include "Listener.h"
#include "Diagnostic1.h"
#include "Diagnostic2.h"
#include "Diagnostic3.h"
#include "Summarizer.h"
#include <thread>
#include <iostream>
using namespace std;

// 主函数
int main() {
    CanListener listener;
    Diagnostic1 diagnostic1(listener);
    Diagnostic2 diagnostic2(listener);
    Diagnostic3 diagnostic3(listener);
    Summarizer summarizer({&diagnostic1, &diagnostic2, &diagnostic3});

    // 初始化CAN套接字
    listener.Sockets_Init();

    // 启动监听线程
    std::thread listenerThread(&CanListener::Listen_Loop, &listener);
    
    // 启动诊断线程
    diagnostic1.start();
    diagnostic2.start();
    diagnostic3.start();

	summarizer.start();

    std::cout << "Main thread running!" << std::endl;

    // 等待监听线程结束
    listenerThread.join();
    
    // 停止所有诊断线程
	listener.Stop();
	summarizer.stop();
    
    // 等待所有诊断线程结束


    std::cout << "Program ended!" << std::endl;
    return EXIT_SUCCESS;
    
}